//
// Created by 19y on 2025/9/22.
//

#include "FreeRTOS.h"
#include "task.h"
#include "event_groups.h"
#include "semphr.h"
#include "logger.h"
#include "lvgl_demo.h"
#include "network.h"
#include "data_codec.h"
#include "ntpclient.h"
#include "aliyunclient.h"
#include "system_api.h"
#include "lwip_demo.h"
#include "freertos_demo.h"
#include "fatfs_task.h"

EventGroupHandle_t g_init_eventgroup=NULL;

SemaphoreHandle_t g_dns_mutex=NULL;
void rtos_init(void)
{
    gateway_mid_init();
    my_lwip_config();
    lvgl_start();
    // xTaskCreate(gateway_init,"gateway_init",512,NULL,tskIDLE_PRIORITY + 1,&gateway_init_handle);
    // xTaskCreate(fatfs_test_task,"fatfs_test_task",643,NULL,tskIDLE_PRIORITY+1,NULL);
    // xTaskCreate(data_codec_init,"data_codec_init",128,NULL,tskIDLE_PRIORITY + 5,NULL);
    xTaskCreate(logger_task,"logger_task",512,NULL,tskIDLE_PRIORITY + 5,NULL);
    xTaskCreate(network_setup_task, "network_setup_task", 512, NULL, tskIDLE_PRIORITY + 4, NULL);
    xTaskCreate(aliyunClient_task,"aliyunClient_task",597,NULL,tskIDLE_PRIORITY + 3,NULL);
    xTaskCreate(ntp_client_task,"ntp_client_task",521,NULL,tskIDLE_PRIORITY + 1,NULL);
    xTaskCreate(sensor_codec,"sensor_codec",700,NULL,tskIDLE_PRIORITY + 1,NULL);
    xTaskCreate(sensor_decode,"sensor_decode",412,NULL,tskIDLE_PRIORITY + 1,NULL);
    xTaskCreate(dashboard_update_task,"dashboard_update_task",570,NULL,tskIDLE_PRIORITY + 1,NULL);
    xTaskCreate(sys_info_daemon,"sys_info_daemon",328,NULL,tskIDLE_PRIORITY + 1,NULL);
    xTaskCreate(fatfs_storage_init,"fatfs_storage_init",328,NULL,tskIDLE_PRIORITY + 1,NULL);
    vTaskStartScheduler();
}

void gateway_mid_init(void)
{
    g_dns_mutex=xSemaphoreCreateMutex();
    g_init_eventgroup=xEventGroupCreate();
}